#include<iostream>
using namespace std;
//模板语法
//1.普通swap
template<class T>
void swapA(T &a,T &b){
    T p=a;
    a=b;
    b=p;
    //缺点，无法对class或者结构体进行交换
}


//2.交换class的显式swap
class people{
public:
    int id;
    string name;
    people(int id,string name){
        this->id=id;
        this->name=name;
    }
};

template<> void swapA<people>(people &a,people &b){
    //实现类的交换，而且是同名函数，应该属于重载
    swapA(a.id,b.id);
    swapA(a.name,b.name);//调用已经写好的，实现代码复用

}

int main(){
    int a=1,b=0;
    swapA(a,b);//如果函数名为swap不会通过编译，原因是swap和g++自带的冲突
    cout<<a<<" "<<b<<endl;

    people A(1,"lzc"),B(2,"cc");
    swapA(A,B);//交换两个函数的内容
    cout<<A.id<<"  "<<A.name<<endl;
    cout<<B.id<<"  "<<B.name<<endl;
    return 0;
}
